/*
 * Gsoft开发框架
 * Copyright 2015-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.itcs.app.page;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.itcs.app.pay.service.PayService;
import com.itcs.app.util.PayChannelCode;
import com.itcs.box.util.DateUtils;

/**
 * @author LiuPeng
 * @date 2017年12月20日
 * 
 */
@Controller
@RequestMapping("/trans")
public class PayPageController {

	private Log logger = LogFactory.getLog(getClass());

	@Autowired
	private PayService payService;

	/**
	 * 扫码支付，使用公众号实现
	 * 
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/qrcode")
	public String qrcode(HttpServletRequest request) {
		String pageUrl = "/wap3";
		try {
			String userAgent = request.getHeader("user-agent").toLowerCase();
			String payChannelCode = PayChannelCode.微信支付;
			if (userAgent.contains("alipayclient")) {
				payChannelCode = PayChannelCode.支付宝支付;
			}

			pageUrl = payService.qrcode(request, payChannelCode);
		} catch (Exception e) {
			logger.error("主扫失败处理," + e.getMessage(), e);
		}
		return pageUrl;
	}

	@RequestMapping(value = "/test")
	public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView model = new ModelAndView("/qrcode_test");
		model.addObject("transacSeq", "G000000000000000" + DateUtils.getToday("yyyyMMddHHmmss" + "00"));
		model.addObject("tollTime", new Date().getTime());
		return model;
	}
}
